#include "txtcardreader.h"
#include <QApplication>
txtcardreader::txtcardreader(QString connStr):AbstractCardReader(connStr)
{
    this->path = connStr;
}

QList<Card>* txtcardreader::readCards()
{
    QList<Card>* cards = new QList<Card>;
    QString fp = QApplication::applicationDirPath()+"\\"+path;
    QFile file(fp);

    if(file.open(QFile::ReadOnly | QFile::Text))
    {
        QTextStream in(&file);
        QString line = in.readLine();

        while (!line.isNull())
        {
            QRegExp rx("(\\;|\\=)");
            QStringList list = line.split(rx);
            Card tmpCard(list[1].toInt(), list[3], list[5], list[7]);
            cards->push_back(tmpCard);

            line = in.readLine();
        }

        return cards;
    }
}
